import redis
import json


def get_config():
    with open("config.json") as CONFIG:
        return json.load(CONFIG)


def redis_con():
    local_config = get_config()
    if local_config.get("env"):
        if local_config["env"] == "live":
            pool = redis.ConnectionPool(host=local_config["redis"]["host"], password=local_config["redis"]["auth"],
                                        db=0, decode_responses=True)
            return redis.Redis(connection_pool=pool)
    pool = redis.ConnectionPool(host=local_config["redis"]["host"], password=local_config["redis"]["auth"], db=1,
                                decode_responses=True)
    return redis.Redis(connection_pool=pool)
